<template>
<view>
    <mian-index ref="childer" @send="getSonValue"></mian-index>
    <view class="btns">
        <button class="btn_appointment arc_button del_btn" type="default" @click="delPop">
            删除就诊人
        </button>
        <button class="btn_appointment arc_button" type="default" @click="last">
            编辑就诊人
        </button>

    </view>

    <uni-popup ref="delDialog" type="dialog">
        <view class="inputDialog">
            <view class="title">
                确定要删除该就诊人吗？
            </view>
            <view class="button-bottom">
                <view class="cancel" @click="dialogClose">取消</view>
                <view @click="dialogConfirm" class="green_words">确定</view>
            </view>
        </view>
    </uni-popup>
</view>
</template>

<script>
import {
    childer
} from '@/pagesSub/components/ofPatient.vue';
import {
    patientList,
    doctorList,
    deletePatient
} from '@/api/prescribing.js';
export default {
    components: {
        'mian-index': childer,
    },
    data() {
        return {
            info: [],
            choosePeopleInfo: [],
            sonvalue: {},
            queryParams: {
                pageNum: 1,
                pageSize: 10,
            },
            medicals: [],
            patientId: '',
        };
    },
    onLoad: function (option) {
        if (option.medicals) {
            let medical = JSON.parse(decodeURIComponent(option.medicals));
            this.medicals = medical;
        }
    },
    onShow() {
        this.$refs.childer.patientListInfo();
        this.$refs.childer.peopleNumber();
        this.sonvalue = {};
    },
    methods: {
        // 删除就诊人弹窗
        dialogClose() {
            this.$refs.delDialog.close();
            // this.doctorinfo()
        },
        dialogConfirm() {
            uni.showLoading({
                title: '加载中',
            });

            // console.log(this.sonvalue.patientId, this.patientId, '就诊恶人999---')
            // return
            deletePatient(this.sonvalue.patientId)
                .then((res) => {
                    uni.hideLoading();
                    if (res.code == 200) {
                        uni.showToast({
                            title: '已删除',
                            icon: 'none',
                            duration: 1000,
                        });
                        this.dialogClose();
                        this.queryParams.pageNum = 1;
                        this.listData = [];
                        setTimeout(() => {
                            this.$refs.childer.patientListInfo();
                            this.$refs.childer.peopleNumber();
                            this.sonvalue = {};

                        }, 1000);
                    }
                })
                .catch((err) => {
                    uni.hideLoading();
                    uni.showToast({
                        title: '删除失败',
                        duration: 3000,
                        icon: 'none',
                    });
                    console.log('删除失败错误#', err);
                });
        },
        delPop() {
            if (this.sonvalue && this.sonvalue.patientId) {
                this.$refs.delDialog.open();
                // uni.navigateTo({
                //     url: `/pagesSub-My/my/editPatients?patientId=${this.sonvalue.patientId}`,
                // });
            } else {
                uni.showToast({
                    title: '请选择就诊人',
                    icon: 'none',
                    duration: 3000,
                });
            }

        },
        getSonValue: function (res) {
            this.sonvalue = res;
            this.patientid = res.patientId;
        },
        patientListInfo() {
            let _this = this;
            uni.showLoading({
                title: '加载中',
            });
            patientList(_this.queryParams)
                .then((res) => {
                    _this.info = res.rows;
                    uni.hideLoading();
                })
                .catch((res) => {
                    uni.hideLoading();
                });
        },
        doctorLists() {
            let _this = this;
            uni.showLoading({
                title: '加载中',
            });
            doctorList(_this.queryParams)
                .then((res) => {
                    // _this.info=res.rows;
                    uni.hideLoading();
                })
                .catch((res) => {
                    uni.hideLoading();
                });
        },

        last() {
            if (this.sonvalue && this.sonvalue.patientId) {
                uni.navigateTo({
                    url: `/pagesSub-My/my/editPatients?patientId=${this.sonvalue.patientId}`,
                });
            } else {
                uni.showToast({
                    title: '请选择就诊人',
                    icon: 'none',
                    duration: 3000,
                });
            }
        },
    },
};
</script>

<style scoped>
.content {
    padding: 10rpx;
    display: flex;
    flex-wrap: wrap;
}

.content view {
    /* width: 150rpx; */
    margin-left: 10rpx;
    padding: 10rpx;
    background-color: #ffffff;
    border-radius: 10rpx;
    /* margin-right: 20rpx; */
    margin-bottom: 20rpx;
}

.introduce {
    font-size: 29rpx;
}

.introduce text {
    margin-right: 20rpx;
}

.btn_appointment {
    margin-top: 40rpx;
    background: -webkit-linear-gradient(#77e2a4, #4ccdbc);
    color: #ffffff;
}

.del_btn {
    background: #f4f4f4 !important;
    /* //-webkit-linear-gradient(#77E2A4, #4CCDBC); */
    color: #4ccdbc;
    border: 1px solid #4ccdbc !important;
}

/* 弹出框 */
.inputDialog {
    width: 600rpx;
    border-radius: 10rpx;
    background-color: #ffffff;
}

/deep/.input-padding {
    padding: 20rpx !important;
}

.inputDialog>.title {
    text-align: center;
    padding: 30rpx;
    font-size: 32rpx;
    line-height: 50rpx;
}

.button-bottom {
    display: flex;
    border-top: 1px solid #f0f0f0;
}

.button-bottom view {
    width: 50%;
    padding: 20rpx 0 20rpx 0;
    font-size: 32rpx;
    text-align: center;
}

.cancel {
    border-right: 1px solid #f0f0f0;
}

/* 绿色字体 */
.green_words {
    color: #62c0ad;
}

.btns {
    display: flex;
    justify-content: space-between;
    /* margin-top: 100rpx; */
}

.arc_button {
    width: 45%;
}
</style>
